package coop.bancocredicoop.proyectos.gd.query.customer;

import org.hibernate.classic.Session;
import org.hibernate.Transaction;

import coop.bancocredicoop.proyectos.gd.domain.Customer;
import coop.bancocredicoop.proyectos.gd.hibernate.HibernateUtil;

public class InsertCustomer {

	public Customer run(Customer customer) throws Exception {

		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx = null;

		try {
			tx = session.beginTransaction();

			session.save(customer);

			tx.commit();
		}
		catch (Exception e) {
			if (tx != null)
				tx.rollback();
			throw e;
		} finally {
			session.close();
		}

		return customer;

	}

}
